home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte11 / devcaps / phone.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  23KB  |  648 lines

  1. #include <windows.h> 
  2. #include <windowsx.h> 
  3. #include "phone.h" 
  4. #include "tapi.h"
  5.  
  6. #define BUFSIZE 256
  7. #define APIHIVERSION     0x00010028    /* 1.40 */
  8. #define APILOWVERSION    0x00010000    /* 1.0 */
  9. #define EXTHIVERSION     0x00010005    /* 1.5 */
  10. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  11. #define MAX_PHONE        2
  12. #define OWNER            0
  13. #define MONITOR        1
  14.  
  15. LPCTSTR lpszAppName = "phoneGetDevCaps";
  16. LPCTSTR lpszTitle   = "phoneGetDevCaps"; 
  17.  
  18.  
  19. #if defined (WIN32)
  20.     #define IS_WIN32 TRUE
  21. #else
  22.     #define IS_WIN32 FALSE
  23. #endif
  24.  
  25. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  26. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  27. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  28.  
  29. HINSTANCE hInst;   // current instance
  30. HWND hWnd;         // parent window handle
  31. HWND hListWnd;     // listbox
  32. HDC  hdc;
  33. TEXTMETRIC  tm ;
  34.  
  35. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  36.  
  37.  
  38. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  39.                       LPTSTR lpCmdLine, int nCmdShow)
  40. {
  41.    MSG      msg;
  42.    WNDCLASS wc;
  43.  
  44.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  45.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  46.    wc.cbClsExtra    = 0;                      
  47.    wc.cbWndExtra    = 0;                      
  48.    wc.hInstance     = hInstance;              
  49.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  50.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  51.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  52.    wc.lpszMenuName  = lpszAppName;              
  53.    wc.lpszClassName = lpszAppName;              
  54.  
  55.    if ( IS_WIN95 )
  56.    {
  57.       if ( !RegisterWin95( &wc ) )
  58.          return( FALSE );
  59.    }
  60.    else if ( !RegisterClass( &wc ) )
  61.       return( FALSE );
  62.  
  63.    hInst = hInstance; 
  64.  
  65.    hWnd = CreateWindow( lpszAppName, 
  66.                         lpszTitle,    
  67.                         WS_OVERLAPPEDWINDOW, 
  68.                         CW_USEDEFAULT, 0, 
  69.                         CW_USEDEFAULT, 0,  
  70.                         NULL,              
  71.                         NULL,              
  72.                         hInstance,         
  73.                         NULL               
  74.                       );
  75.  
  76.    if ( !hWnd ) 
  77.       return( FALSE );
  78.  
  79.    ShowWindow( hWnd, nCmdShow ); 
  80.    UpdateWindow( hWnd );         
  81.  
  82.    while( GetMessage( &msg, NULL, 0, 0) )   
  83.    {
  84.       TranslateMessage( &msg ); 
  85.       DispatchMessage( &msg );  
  86.    }
  87.  
  88.    return( msg.wParam ); 
  89. }
  90.  
  91.  
  92. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  93. {
  94.     WNDCLASSEX wcex;
  95.  
  96.    wcex.style         = lpwc->style;
  97.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  98.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  99.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  100.    wcex.hInstance     = lpwc->hInstance;
  101.    wcex.hIcon         = lpwc->hIcon;
  102.    wcex.hCursor       = lpwc->hCursor;
  103.    wcex.hbrBackground = lpwc->hbrBackground;
  104.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  105.    wcex.lpszClassName = lpwc->lpszClassName;
  106.  
  107.    // Added elements for Windows 95.
  108.    //...............................
  109.    wcex.cbSize = sizeof(WNDCLASSEX);
  110.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  111.                             IMAGE_ICON, 16, 16,
  112.                             LR_DEFAULTCOLOR );
  113.             
  114.    return RegisterClassEx( &wcex );
  115. }
  116.  
  117. typedef struct tagMYINFO    // general application information
  118. {
  119.     HPHONEAPP phoneApp;      // instance handle TAPI gives back to us                                                                              through phoneInitialize()
  120.     DWORD dwNumDevices;     // number of available devices
  121.     DWORD dwAPIVersion;     // API version the phone supports
  122.     DWORD dwExtVersion;        // extended version
  123. } MYINFO;
  124.  
  125. typedef struct tagPHONEINFO  // information on an open phone
  126. {
  127.    HPHONE     hPhone;           // handle to the phone as returned by phoneOpen 
  128.     DWORD      dwDeviceID;            // device ID of the phone device
  129.     DWORD        dwRequestID;
  130.     char       szPhoneName[128]; // the phone's name 
  131. }PHONEINFO;
  132.  
  133. MYINFO myInfo;          //instance of MYINFO structure
  134. PHONEINFO myPhoneInfo[MAX_PHONE];  //instance of myPhoneInfo structure
  135.  
  136. LONG lRet;        //return code
  137. char buf[BUFSIZE];    // buffer for debug message
  138. char DataBuf[BUFSIZE]; //get/set data buffer;
  139.  
  140. DWORD i;
  141. DWORD dwHookSwitchDevs;
  142. DWORD dwLampMode;
  143. DWORD dwRingMode;
  144. DWORD dwRingVolume;
  145. DWORD dwHookSwitchVolume;
  146. DWORD dwPhoneStates;
  147. DWORD dwButtonModes;
  148. DWORD dwButtonStates;
  149. DWORD dwGain;
  150. HICON hIcon;
  151.  
  152. LONG lRet;
  153. char buf[BUFSIZE];
  154.  
  155. PHONECAPS*             pPhoneCaps;
  156. PHONEBUTTONINFO*  pButtonInfo;
  157. VARSTRING*            pVarString;
  158. PHONESTATUS*        pPhoneStatus;
  159. PHONEEXTENSIONID    ext_id;                                             
  160.  
  161.  
  162. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  163. {
  164.    switch( uMsg )
  165.    {
  166.       case WM_COMMAND :
  167.          switch( LOWORD( wParam ) )
  168.          {
  169.             case IDM_RUN  :
  170.                    pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  171.                     pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  172.                     lRet = phoneGetDevCaps(myInfo.phoneApp,myPhoneInfo[OWNER].dwDeviceID,
  173.                             myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  174.                     if (lRet == 0)
  175.                    {     
  176.                        wsprintf(buf, "phoneGetDevCaps succeeded!");
  177.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  178.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwProviderInfoOffset));
  179.                   strcat( buf, " is the phone providor's name." );
  180.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  181.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwPhoneNameOffset));
  182.                   strcat( buf, " is the phone's name." );
  183.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  184.                         wsprintf( buf,"The Permanent Phone ID is: x%lx", pPhoneCaps->dwPermanentPhoneID);
  185.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  186.                         wsprintf( buf,"The String Format is: x%lx", pPhoneCaps->dwStringFormat);
  187.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  188.                         wsprintf( buf,"The Phone States are: x%lx", pPhoneCaps->dwPhoneStates);
  189.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  190.                         wsprintf( buf,"The Hookswitch Devices are: x%lx", pPhoneCaps->dwHookSwitchDevs);
  191.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  192.                         wsprintf( buf,"The Handset Hookswitch Modes are: x%lx", pPhoneCaps->dwHandsetHookSwitchModes);
  193.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  194.                         wsprintf( buf,"The Speaker Hookswitch Modes are: x%lx", pPhoneCaps->dwSpeakerHookSwitchModes);
  195.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  196.                         wsprintf( buf,"The Headset Hookswitch Modes are: x%lx", pPhoneCaps->dwHeadsetHookSwitchModes);
  197.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  198.                         wsprintf( buf,"The Volume Flags are: x%lx", pPhoneCaps->dwVolumeFlags);
  199.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  200.                         wsprintf( buf,"The Gain Flags are: x%lx", pPhoneCaps->dwGainFlags);
  201.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  202.                         wsprintf( buf,"The number of display Rows is: x%lx", pPhoneCaps->dwDisplayNumRows);
  203.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  204.                         wsprintf( buf,"The number of display Columns is: x%lx", pPhoneCaps->dwDisplayNumColumns);
  205.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  206.                         wsprintf( buf,"The number of Ring Modes is: x%lx", pPhoneCaps->dwNumRingModes);
  207.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  208.                         wsprintf( buf,"The number of Button Lamps is: x%lx", pPhoneCaps->dwNumButtonLamps);
  209.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  210.                    }
  211.                    else 
  212.                    {     
  213.                         wsprintf( buf,"phoneGetDevCaps failed, err=x%lx", lRet);
  214.                        phoneError(lRet);
  215.                    }    
  216.                 
  217.                    free (pPhoneCaps);                                  
  218.                    break;
  219.  
  220.             case IDM_EXIT :
  221.                for (i = 0; i < myInfo.dwNumDevices; i++)
  222.                     phoneClose(myPhoneInfo[i].hPhone);
  223.                 
  224.                    phoneShutdown(myInfo.phoneApp);
  225.                DestroyWindow( hWnd );
  226.                break;
  227.                            
  228.             case IDM_ABOUT :
  229.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  230.                 break;
  231.          }
  232.                 
  233.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  234.  
  235.       
  236.        case WM_CREATE :
  237.  
  238.           hdc = GetDC (hWnd) ;
  239.           GetTextMetrics (hdc, &tm) ;
  240.           ReleaseDC (hWnd, hdc) ;
  241.  
  242.           hListWnd = CreateWindowEx( 0, "listbox", 
  243.                         " ",    
  244.                         WS_CHILD | WS_VISIBLE,  
  245.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  246.                         tm.tmAveCharWidth * 16 +
  247.                                    GetSystemMetrics (SM_CXVSCROLL), 
  248.                         tm.tmHeight * 5,  
  249.                         hWnd,              
  250.                         NULL,              
  251.                         hInst,         
  252.                         NULL               
  253.                         );
  254.       
  255.              //phoneInitialize
  256.                //...............................................
  257.             lRet = phoneInitialize(&myInfo.phoneApp, hInst, phoneCallback, lpszAppName, &myInfo.dwNumDevices);
  258.             if (lRet == 0) 
  259.             {
  260.                 
  261.                wsprintf(buf, "phoneInitialize succeeded!");
  262.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  263.             }
  264.                
  265.                else 
  266.                {
  267.                    wsprintf( buf,"phoneInitialize failed, err=x%lx",lRet);
  268.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  269.                     phoneError(lRet);
  270.                     break;
  271.             }                    
  272.                
  273.             //phoneNegotiateAPIVersion
  274.                   //...............................................
  275.             lRet = phoneNegotiateAPIVersion(myInfo.phoneApp, 0, APILOWVERSION, APIHIVERSION, 
  276.                                                     &myInfo.dwAPIVersion, &ext_id);
  277.             if (lRet == 0)                        
  278.             {
  279.                wsprintf(buf, "phoneNegotiateAPIVersion succeeded!");
  280.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  281.             }
  282.                   else 
  283.                   {
  284.                    wsprintf(buf, "phoneNegotiateAPIVersion failed, err=x%lx", lRet);
  285.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  286.                     phoneError(lRet);
  287.                     phoneShutdown(myInfo.phoneApp);
  288.                break;
  289.              }
  290.  
  291.                //phoneNegotiateExtVersion
  292.                //...............................................
  293.             lRet = phoneNegotiateExtVersion(myInfo.phoneApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  294.                                                 EXTHIVERSION, &myInfo.dwExtVersion);
  295.             if (lRet == 0)                        
  296.             {
  297.                     wsprintf(buf, "phoneNegotiateExtVersion succeeded!");
  298.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  299.               }
  300.                   else 
  301.                {
  302.                     wsprintf(buf, "phoneNegotiateExtVersion failed, err=x%lx", lRet);
  303.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  304.                       phoneError(lRet);
  305.                }
  306.  
  307.             //phoneOpen
  308.                //................................................................
  309.                for (i = 0; i < myInfo.dwNumDevices; i++)
  310.                {
  311.                    if ( i == 0)
  312.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  313.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_OWNER);
  314.                    else
  315.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  316.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_MONITOR);
  317.                    
  318.                    if (lRet == 0)
  319.                    {
  320.                      wsprintf(buf, "phoneOpen succeeded!");
  321.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  322.                   pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  323.                       pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  324.                          
  325.                       phoneGetDevCaps(myInfo.phoneApp,i,
  326.                       myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  327.                       strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwProviderInfoOffset));
  328.                   strcat( buf, " is the phone providor's name." );
  329.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  330.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwPhoneNameOffset));
  331.                      
  332.                   if (i == 0)
  333.                   {
  334.                      strcat( buf, " is the phone's name opened with OWNER privilege." );
  335.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  336.                   }
  337.                   else
  338.                   {
  339.                      strcat( buf, " is the phone's name opened with MONITOR privilege." );
  340.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  341.                   }
  342.                }
  343.                    else 
  344.                    {
  345.                        wsprintf( buf,"phoneOpen failed, err=x%lx", lRet);
  346.                        phoneError(lRet);
  347.                       break;
  348.                }
  349.                   } 
  350.  
  351.             break;
  352.       
  353.       case WM_SIZE:
  354.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  355.          break;
  356.  
  357.       case WM_DESTROY :
  358.          PostQuitMessage(0);
  359.          break;
  360.             
  361.       default :
  362.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  363.    }
  364.  
  365.    return( 0L );
  366. }
  367.  
  368.  
  369.  
  370. /****************************************************************************
  371.     FUNCTION: phoneCallback
  372.     PURPOSE:  callback function handles phone events
  373. ****************************************************************************/
  374. LRESULT CALLBACK phoneCallback (DWORD  dwDevice, DWORD dwMsg,
  375.                                 DWORD dwCallbackInst, DWORD dwParam1,
  376.                                 DWORD dwParam2,DWORD dwParam3)
  377. {
  378.     
  379.     switch (dwMsg)
  380.     {
  381.         case PHONE_REPLY:
  382.             if (dwParam1 == myPhoneInfo[OWNER].dwRequestID) 
  383.                    if (dwParam2 != 0)
  384.                 {
  385.                        wsprintf( buf,"Function failed, err=x%lx", lRet);
  386.                        phoneError(lRet);
  387.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  388.                    }
  389.             break;       
  390.  
  391.         case PHONE_STATE:
  392.         
  393.             if (dwParam1 == PHONESTATE_RINGMODE)
  394.             {
  395.                 lRet = phoneGetRing(myPhoneInfo[OWNER].hPhone, &dwRingMode, &dwRingVolume);
  396.                 if (lRet == 0)
  397.                {
  398.                 wsprintf(buf, "phoneGetRing succeeded!");
  399.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  400.                if (dwRingMode == 0)
  401.                     {
  402.                         wsprintf(buf, "The phone device is currently not ringing.");
  403.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  404.                }
  405.                     else
  406.                     {
  407.                         wsprintf(buf, "The phone is ringing with a Ring Mode pattern of x%lx", dwRingMode);
  408.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  409.                    wsprintf(buf, "The phnes's Ring Volume is x%lx", dwRingVolume);
  410.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  411.                     }
  412.                }
  413.                  else 
  414.                {
  415.                     wsprintf( buf,"phoneGetRing failed, err=x%lx", lRet);
  416.                    phoneError(lRet);
  417.                }        
  418.               
  419.               break;
  420.               }
  421.             
  422.  
  423.             if (dwParam1 == PHONESTATE_SPEAKERHOOKSWITCH)
  424.             {   
  425.                 lRet = phoneGetHookSwitch(myPhoneInfo[OWNER].hPhone, &dwHookSwitchDevs);
  426.                 if (lRet == 0)
  427.                {
  428.                wsprintf(buf, "phoneGetHookSwitch succeeded!");
  429.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  430.                
  431.                if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_SPEAKER)
  432.                     {
  433.                         wsprintf(buf, "The phone's HookSwitch Speaker is offhook!");
  434.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  435.                     }
  436.                     else
  437.                     {
  438.                    wsprintf(buf, "The phone's HookSwitch Speaker is onhook!");
  439.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  440.                     }
  441.  
  442.               }
  443.                  else 
  444.                {
  445.                       wsprintf( buf,"phoneGetHookSwitch failed, err=x%lx", lRet);
  446.                    phoneError(lRet);
  447.                }    
  448.             break;                
  449.             }
  450.  
  451.             if (dwParam1 == PHONESTATE_SPEAKERVOLUME)
  452.             {   
  453.                 lRet = phoneGetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwHookSwitchVolume);
  454.                if (lRet == 0)
  455.                {
  456.                 wsprintf(buf, "phoneGetVolume succeeded!");
  457.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  458.                wsprintf(buf, "The current volume for the Speaker Hookswitch is x%lx", dwHookSwitchVolume);
  459.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  460.                }
  461.                  else 
  462.                {
  463.                     wsprintf( buf,"phoneGetVolume failed, err=x%lx", lRet);
  464.                    phoneError(lRet);
  465.                }    
  466.             break;                
  467.             }
  468.  
  469.             if (dwParam1 == PHONESTATE_SPEAKERGAIN)
  470.             {   
  471.                 lRet = phoneGetGain(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwGain);
  472.                 if (lRet == 0)
  473.                {
  474.                   wsprintf(buf, "phoneGetGain succeeded!");
  475.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  476.                     wsprintf(buf, "The current Gain is x%lx", dwGain);
  477.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  478.                }
  479.                  else 
  480.                {
  481.                       wsprintf( buf,"phoneGetGain failed, err=x%lx", lRet);
  482.                     phoneError(lRet);
  483.                }
  484.             break;                
  485.             }
  486.             
  487.             if (dwParam1 == PHONESTATE_DISPLAY)
  488.             {   
  489.                 pVarString = (VARSTRING *) calloc (1, sizeof(VARSTRING)+1000);
  490.                 pVarString->dwTotalSize = sizeof(VARSTRING) + 1000;
  491.                 lRet = phoneGetDisplay(myPhoneInfo[OWNER].hPhone, pVarString);
  492.                 if (lRet == 0)
  493.                {
  494.                   wsprintf(buf, "phoneGetDisplay succeeded!");
  495.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  496.                strcpy(buf, lpszTitle);
  497.                //strcpy(buf, ((LPSTR)(pVarString)+pVarString->dwStringOffset));
  498.                strcat( buf, " is the current phone display." );
  499.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  500.                }
  501.                  else 
  502.                {
  503.                    wsprintf( buf,"phoneGetDisplay failed, err=x%lx", lRet);
  504.                   phoneError(lRet);
  505.                }    
  506.                     
  507.                 free (pVarString);
  508.                 break;
  509.               }
  510.    }
  511.    return (TRUE);
  512.  
  513.  
  514. /****************************************************************************
  515.     FUNCTION: phoneError
  516.     PURPOSE:  phone error messages
  517. ****************************************************************************/
  518. void phoneError (LONG lrc)
  519. {
  520.  switch (lrc) {
  521.     case PHONEERR_INVALAPPHANDLE:
  522.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  523.        break;
  524.     case PHONEERR_BADDEVICEID:
  525.        MessageBox (hWnd,"The specified phone device ID is out of range.", "", 
  526.                    MB_OK);
  527.        break;
  528.     case PHONEERR_INCOMPATIBLEAPIVERSION:
  529.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  530.        break;
  531.     
  532.     case PHONEERR_INVALBUTTONLAMPID:
  533.        MessageBox (hWnd, "Invalid Button Lamp ID.", "", MB_OK);
  534.        break;
  535.  
  536.     case PHONEERR_INVALBUTTONMODE:
  537.        MessageBox (hWnd, "Invalid Button Mode.", "", MB_OK);
  538.        break;
  539.  
  540.     case PHONEERR_INVALBUTTONSTATE:
  541.        MessageBox (hWnd, "Invalid Button State", "", MB_OK);
  542.        break;
  543.  
  544.     case PHONEERR_INUSE:
  545.        MessageBox (hWnd, "Phone in Use.", "", MB_OK);
  546.        break;
  547.     
  548.     case PHONEERR_INVALHOOKSWITCHDEV:
  549.        MessageBox (hWnd, "Invalid Hookswitch Device.", "", MB_OK);
  550.        break;
  551.  
  552.     case PHONEERR_INVALHOOKSWITCHMODE:
  553.        MessageBox (hWnd, "Invalid Hookswitch Device Mode.", "", MB_OK);
  554.        break;
  555.  
  556.     case PHONEERR_INVALLAMPMODE:
  557.        MessageBox (hWnd, "Invalid Lamp Mode.", "", MB_OK);
  558.        break;
  559.      
  560.     case PHONEERR_INCOMPATIBLEEXTVERSION:
  561.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  562.        break;
  563.     case PHONEERR_NOMEM:
  564.        MessageBox (hWnd, "No memory","", MB_OK);
  565.        break;
  566.     case PHONEERR_NODRIVER:
  567.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  568.        break;
  569.     case PHONEERR_RESOURCEUNAVAIL:
  570.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  571.        break;
  572.     case PHONEERR_ALLOCATED:
  573.        MessageBox (hWnd, "Allocation error", "", MB_OK);
  574.        break;
  575.     case PHONEERR_INVALDATAID:
  576.        MessageBox (hWnd, "The data ID is out of range.", "", MB_OK);
  577.        break;
  578.     case PHONEERR_INVALDEVICECLASS:
  579.        MessageBox (hWnd, "The device class was invalid.", "", MB_OK);
  580.        break;
  581.     case PHONEERR_INVALPOINTER:
  582.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  583.                    "", MB_OK);
  584.        break;
  585.     case PHONEERR_OPERATIONFAILED:
  586.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  587.        break;
  588.     case PHONEERR_INVALPHONEHANDLE:
  589.        MessageBox (hWnd, "Invalid phone handle", "", MB_OK);
  590.        break;
  591.     case PHONEERR_INVALPHONESTATE :
  592.        MessageBox (hWnd, "Invalid call state for this function.", "", MB_OK);
  593.        break;
  594.     case PHONEERR_INVALPRIVILEGE:
  595.        MessageBox (hWnd, "Invalid privilege for this function.", "", MB_OK);
  596.        break;
  597.     case PHONEERR_NODEVICE:
  598.        MessageBox (hWnd, "No associated device for given class",
  599.                    "", MB_OK);
  600.        break;
  601.     case PHONEERR_OPERATIONUNAVAIL:
  602.        MessageBox (hWnd, "The operation is unavailable",
  603.                    "", MB_OK);
  604.        break;
  605.     case PHONEERR_INVALPARAM:
  606.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  607.        break; 
  608.  
  609.     case PHONEERR_INVALRINGMODE:
  610.             MessageBox(hWnd, "Invalid Ring Mode", "", MB_OK);
  611.        break; 
  612.  
  613.     }
  614.     
  615.              
  616. }
  617.  
  618. LRESULT CALLBACK About( HWND hDlg,           
  619.                         UINT message,        
  620.                         WPARAM wParam,       
  621.                         LPARAM lParam)
  622. {
  623.    switch (message) 
  624.    {
  625.        case WM_INITDIALOG: 
  626.                return (TRUE);
  627.  
  628.        case WM_COMMAND:                              
  629.                if (   LOWORD(wParam) == IDOK         
  630.                    || LOWORD(wParam) == IDCANCEL)    
  631.                {
  632.                        EndDialog(hDlg, TRUE);        
  633.                        return (TRUE);
  634.                }
  635.                break;
  636.    }
  637.  
  638.    return (FALSE); 
  639. }
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.